import { envConfig } from '../config/index.js'
import { handleStore } from '../init.js'
import getShareId from './shareId'

const mpCodeconfig = [
  { id: 101, page: 'pages/tabbar/card/card', qrCodeType: 5, extAttribute: { originId: 1003, sourceType: 4 } }, // 名片分享组件名片页
  { id: 201, page: 'subs/mall/pages/manual-vertical/manual-vertical', qrCodeType: 10, extAttribute: { sourceType: 4 } }, // 名片码页面手册竖屏
  { id: 202, page: 'subs/mall/pages/manual-horizontal/manual-horizontal', qrCodeType: 10, extAttribute: { sourceType: 4 } }, // 名片码页面手册横屏
  { id: 203, page: 'pages/tabbar/card/card', extAttribute: { originId: 1001 } }, // 名片码页面手册横屏
  { id: 1001, page: null, qrCodeType: 10, extAttribute: { originId: 1015, sourceType: 4 } }, // 手册海报码
  { id: 1301, page: 'subs/dynamic/pages/dynamic-detail/dynamic-detail', qrCodeType: 8, extAttribute: { originId: 1016, sourceType: 17 } }, // 图文/视频动态海报码
  { id: 1302, page: 'subs/website/pages/web-view/web-view', qrCodeType: 8, extAttribute: { originId: 1016, sourceType: 17 } }, // 文章动态海报码
  { id: 1401, page: 'subs/interactive/pages/activity-detail/activity-detail', qrCodeType: 5, extAttribute: { originId: -1, sourceType: 2 } }, // 文章动态海报码
]

const mpCodeConfigMap = {}
mpCodeconfig.forEach(({ id, ...item }) => {
  mpCodeConfigMap[id] = item
})

function getMpCodeConfig(id, { extAttribute = {}, ...params }) {
 const u = handleStore('userInfo').userInfo
  const { userId } = u.__userInfo
  const { extAttribute: fixedExtAttribute, ...fixedParams } = mpCodeConfigMap[id]
  return {
    companyId: envConfig.companyId,
    ...fixedParams,
    ...params,
    extAttribute: {
      id: params.id,
      routeId: getShareId(),
      forwardUserId: userId,
      ...fixedExtAttribute,
      ...extAttribute
    }
  }
}

export { getMpCodeConfig }
